<?php
require 'db.php';
$strsql = "select * from major";
$result = mysqli_query($link, $strsql);
$data_major = mysqli_fetch_all($result);

if (isset($_POST['sub'])){
    $name = $_POST['name'];
    $num = $_POST['num'];
    $subject = $_POST['subject'];
    $major = $_POST['major'];
    
    $sql = "insert into student (name,num,subject,major) values ('".$name."','".$num."','".$subject."','".$major."')";
    $query = mysqli_query($link, $sql);
    if ($query){
        echo "<script>window.location.href='student.php';</script>";
        exit;
    }else{
        echo "<script>alert('添加失败！')</script>";
        echo "<script>window.history.go(-1);</script>";
        exit;
    }
}



mysqli_free_result($result);
mysqli_close($link);

require 'new.html';

?>